package com.ruoyi.project.wenyanwen.itemmapper.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wenyanwen.itemmapper.domain.ItemMapper;
import com.ruoyi.project.wenyanwen.itemmapper.service.IItemMapperService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 内容映射Controller
 * 
 * @author shixiangwen
 * @date 2020-08-13
 */
@Controller
@RequestMapping("/wenyanwen/itemmapper")
public class ItemMapperController extends BaseController
{
    private String prefix = "wenyanwen/itemmapper";

    @Autowired
    private IItemMapperService itemMapperService;

    @RequiresPermissions("wenyanwen:itemmapper:view")
    @GetMapping()
    public String itemmapper()
    {
        return prefix + "/itemmapper";
    }

    /**
     * 查询内容映射列表
     */
    @RequiresPermissions("wenyanwen:itemmapper:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ItemMapper itemMapper)
    {
        startPage();
        List<ItemMapper> list = itemMapperService.selectItemMapperList(itemMapper);
        return getDataTable(list);
    }

    /**
     * 导出内容映射列表
     */
    @RequiresPermissions("wenyanwen:itemmapper:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ItemMapper itemMapper)
    {
        List<ItemMapper> list = itemMapperService.selectItemMapperList(itemMapper);
        ExcelUtil<ItemMapper> util = new ExcelUtil<ItemMapper>(ItemMapper.class);
        return util.exportExcel(list, "itemmapper");
    }

    /**
     * 新增内容映射
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存内容映射
     */
    @RequiresPermissions("wenyanwen:itemmapper:add")
    @Log(title = "内容映射", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ItemMapper itemMapper)
    {
        return toAjax(itemMapperService.insertItemMapper(itemMapper));
    }

    /**
     * 修改内容映射
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ItemMapper itemMapper = itemMapperService.selectItemMapperById(id);
        mmap.put("itemMapper", itemMapper);
        return prefix + "/edit";
    }

    /**
     * 修改保存内容映射
     */
    @RequiresPermissions("wenyanwen:itemmapper:edit")
    @Log(title = "内容映射", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ItemMapper itemMapper)
    {
        return toAjax(itemMapperService.updateItemMapper(itemMapper));
    }

    /**
     * 删除内容映射
     */
    @RequiresPermissions("wenyanwen:itemmapper:remove")
    @Log(title = "内容映射", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(itemMapperService.deleteItemMapperByIds(ids));
    }
}
